<?php

namespace App\Model;

use EasySwoole\DDL\Enum\Character;
use EasySwoole\DDL\Enum\Engine;
use EasySwoole\ORM\AbstractModel;
use EasySwoole\ORM\Exception\Exception;
use EasySwoole\ORM\Utility\Schema\Table;
use Throwable;

class t_lvyou extends AbstractModel
{
    protected $tableName = 't_lvyou';
    protected $autoTimeStamp = true; // 自动写入create_time和update_time 这两个字段是int

    /**
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getAccount($where)
    {
        $where['is_deleted'] = 0;
        return $this->order('id', 'desc')->get($where);
    }

    /**
     * @throws Throwable
     * @throws Exception
     */
    public function addAccount($where)
    {
        $this->data($where, false);
        return $this->save();
    }

    public function schemaInfo(bool $isCache = true): Table
    {
        $table = new Table($this->tableName);

        $table->setIfNotExists();
        $table->setTableEngine(Engine::INNODB);
        $table->setTableCharset(Character::UTF8MB4_GENERAL_CI);
        $table->setTableComment('用户缴纳物业费表');

        $table->colInt('id')->setIsAutoIncrement()->setIsPrimaryKey(true)->setColumnComment("ID");
        $table->colVarChar('name', 255)->setDefaultValue(0)->setIsNotNull()->setColumnComment('用户id');
        $table->colVarChar('address', 255)->setDefaultValue(0)->setIsNotNull()->setColumnComment('房屋id');
        $table->colVarChar('lat', 255)->setDefaultValue('')->setColumnComment('订单号');
        $table->colVarChar('lng', 255)->setDefaultValue('')->setColumnComment('唯一标识');
        $table->colVarChar('zht',255)->setDefaultValue(0.00)->setColumnComment('住宅物业基础费用费');
        $table->colVarChar('zhtjg',255)->setDefaultValue(0.00)->setColumnComment('公共区域公摊电费');
        $table->colVarChar('xfx',255)->setDefaultValue(0.00)->setColumnComment('公共垃圾费用');
        $table->colVarChar('info',255)->setDefaultValue(0.00)->setColumnComment('物业费总计');
        $table->colVarChar('jctj', 255)->setDefaultValue(0)->setColumnComment('订单状态：(0未支付,1已支付)');

        return $table;
    }
}